﻿Public Class Compiler
    Private mingWPath As String

    Public Sub New(ByVal mingwPath As String)
        Me.mingWPath = mingwPath
    End Sub

    Public Function Build(ByVal input As String, ByVal output As String, ByVal windowMode As Boolean) As CompileResult
        Dim prc As New Process()
        prc.StartInfo.FileName = mingWPath & "/g++.exe"
        ''prc.StartInfo.Arguments = """" & input & """ -o """ & output & """ -static -mwindows"

        If windowMode Then
            prc.StartInfo.Arguments = """" & input & """ -o """ & output & """ -static -mwindows -Wall"
        Else
            prc.StartInfo.Arguments = """" & input & """ -o """ & output & """"
        End If

        prc.StartInfo.EnvironmentVariables("PATH") &= ";" & mingWPath & ";"
        prc.StartInfo.RedirectStandardError = True
        prc.StartInfo.UseShellExecute = False
        prc.StartInfo.CreateNoWindow = True
        prc.Start()

        Dim result As New CompileResult
        result.Raw = prc.StandardError.ReadToEnd()
        result.ExitCode = prc.ExitCode
        result.Errors = ErrorAnalyzer.GetErrorMessages(result.Raw)
        result.Output = output

        Return result
    End Function
End Class
